package com.yilu.driver.ui.activity;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.is.ui.eventbus.EventCenter;
import com.is.ui.xrecyclerview.universaladapter.ViewHolderHelper;
import com.is.ui.xrecyclerview.universaladapter.recyclerview.CommonRecycleViewAdapter;
import com.is.ui.xrecyclerview.universaladapter.recyclerview.OnItemClickListener;
import com.yilu.driver.R;
import com.yilu.driver.base.BaseActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * 学员管理
 *
 * @author Administrator
 * @date 2017/4/11 0011
 */

public class TraineeMgmtActivity extends BaseActivity implements OnItemClickListener {
    @Bind(R.id.txt_title)
    TextView txtTitle;
    @Bind(R.id.rcl_content)
    RecyclerView rclContent;
    private CommonRecycleViewAdapter<HashMap> adapter;
    private String[] titles = {"学员信息", "教练批次更改", "报考登记", "成绩登记", "阶段结业"
            , "学费管理", "考试场次安排", "毕业学员信息"};

    @Override
    public void initPresenter() {

    }

    @Override
    protected boolean isApplySystemBarColor() {
        return true;
    }

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_trainee_mgmt;
    }

    @Override
    protected void onEventComming(EventCenter eventCenter) {

    }

    @Override
    protected void initViewsAndEvents() {
        txtTitle.setText("学员管理");
        rclContent.setLayoutManager(new GridLayoutManager(this, 3));
        adapter = new CommonRecycleViewAdapter<HashMap>(mContext, R.layout.trainee_mamt_item) {
            @Override
            public void convert(ViewHolderHelper helper, HashMap hashMap) {
                TextView txtName = helper.getView(R.id.txt_name);
                ImageView imgTraineeMgmt = helper.getView(R.id.img_trainee_mgmt);
                txtName.setText((CharSequence) hashMap.get("name"));
                imgTraineeMgmt.setImageResource((Integer) hashMap.get("icon"));
            }
        };
        rclContent.setAdapter(adapter);
        adapter.setOnItemClickListener(this);
        initDatas();
    }

    public void initDatas() {
        adapter.replaceAll(setData());
        adapter.notifyDataSetChanged();
    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    private List<HashMap> setData() {
        List<HashMap> data = new ArrayList<>();
        HashMap hashMap = new HashMap();
        hashMap.put("icon", R.drawable.ic_category_0);
        hashMap.put("name", titles[0]);
        hashMap.put("class", TraineeInfoListActivity.class);
        data.add(hashMap);
        hashMap = new HashMap();
        hashMap.put("icon", R.drawable.ic_category_1);
        hashMap.put("name", titles[1]);
        data.add(hashMap);
        hashMap = new HashMap();
        hashMap.put("icon", R.drawable.ic_category_2);
        hashMap.put("name", titles[2]);
        hashMap.put("class", ApplyExamRegistionActivity.class);
        data.add(hashMap);
        hashMap = new HashMap();
        hashMap.put("icon", R.drawable.ic_category_3);
        hashMap.put("name", titles[3]);
        hashMap.put("class", GradeRegistionActivity.class);
        data.add(hashMap);
        hashMap = new HashMap();
        hashMap.put("icon", R.drawable.ic_category_4);
        hashMap.put("name", titles[4]);
        hashMap.put("class", StageGraduationActivity.class);
        data.add(hashMap);
        hashMap = new HashMap();
        hashMap.put("icon", R.drawable.ic_category_5);
        hashMap.put("name", titles[5]);
        data.add(hashMap);
        hashMap = new HashMap();
        hashMap.put("icon", R.drawable.ic_category_6);
        hashMap.put("name", titles[6]);
        data.add(hashMap);
        hashMap = new HashMap();
        hashMap.put("icon", R.drawable.ic_category_7);
        hashMap.put("name", titles[7]);
        hashMap.put("class", MainActivity.class);
        data.add(hashMap);
        return data;
    }

    @Override
    public void onItemClick(ViewGroup parent, View view, Object o, int position) {
        readyGo((Class<?>) adapter.get(position).get("class"));
    }

    @Override
    public boolean onItemLongClick(ViewGroup parent, View view, Object o, int position) {
        return false;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick(R.id.ib_back)
    public void onClick() {
        finish();
    }

}
